package logic

import (
	"context"
	"user-login/model/mysql"

	"user-login/userrpc/internal/svc"
	"user-login/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HuntAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHuntAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HuntAddLogic {
	return &HuntAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HuntAddLogic) HuntAdd(in *userrpc.HuntAddRequest) (*userrpc.HuntAddResponse, error) {
	// todo: add your logic here and delete this line
	hunt := mysql.Hunt{
		Name:        in.Name,
		Type:        in.Type,
		Address:     in.Address,
		Salary:      float64(in.Salary),
		Experience:  in.Experience,
		Academic:    in.Academic,
		Description: in.Description,
	}
	err := hunt.CreatedHunt(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &userrpc.HuntAddResponse{
		HuntId: int64(hunt.ID),
	}, nil
}
